package io.github.talelin.latticy.service.impl;

import io.github.talelin.autoconfigure.exception.NotFoundException;
import io.github.talelin.latticy.dto.BannerItemDTO;
import io.github.talelin.latticy.mapper.BannerMapper;
import io.github.talelin.latticy.model.BannerItem;
import io.github.talelin.latticy.mapper.BannerItemMapper;
import io.github.talelin.latticy.service.BannerItemService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author tanrentao
 * @since 2021-08-10
 */
@Service
public class BannerItemServiceImpl extends ServiceImpl<BannerItemMapper, BannerItem> implements BannerItemService {

    @Override
    public void update(BannerItemDTO dto, Integer id) {
        BannerItem bannerItem = this.getById(id);
        if (bannerItem == null) {
            throw new NotFoundException(20001);
        }
        BeanUtils.copyProperties(dto, bannerItem);
        this.updateById(bannerItem);
    }

    @Override
    public void delete(Integer id) {
        BannerItem bannerItem = this.getById(id);
        if (bannerItem == null) {
            throw new NotFoundException(20001);
        }
        this.getBaseMapper().deleteById(id);
    }
}
